import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { IotProductCategoryVO, IotProductCategoryQuery, IotProductCategoryForm } from './types'

/**
 * 查询产品分类列表
 * @param query
 */
export const listCategory = (query?: IotProductCategoryQuery): AxiosPromise<IotProductCategoryVO[]> => {
  return request({
    url: '/iot/category/list',
    method: 'get',
    params: query
  })
}

/**
 * 查询产品分类详细
 * @param categoryId
 */
export const getCategory = (categoryId: string | number): AxiosPromise<IotProductCategoryVO> => {
  return request({
    url: '/iot/category/' + categoryId,
    method: 'get'
  })
}

/**
 * 新增产品分类
 * @param data
 */
export const addCategory = (data: IotProductCategoryForm) => {
  return request({
    url: '/iot/category',
    method: 'post',
    data: data
  })
}

/**
 * 修改产品分类
 * @param data
 */
export const updateCategory = (data: IotProductCategoryForm) => {
  return request({
    url: '/iot/category',
    method: 'put',
    data: data
  })
}

/**
 * 删除产品分类
 * @param categoryId
 */
export const delCategory = (categoryId: string | number | Array<string | number>) => {
  return request({
    url: '/iot/category/' + categoryId,
    method: 'delete'
  })
}